﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ChineseSchool.Models.Hethong;
using System.Data;

namespace ChineseSchool.BLL
{
    public class B_UserRole
    {
        private PetaPoco.Database db;
        public B_UserRole()
        {
            db = new PetaPoco.Database("ConnectionString");
        }        

        public List<M_UserRole> GetAlls()
        {
            var UserRole = db.Fetch<M_UserRole>(@";EXEC UserRole_Get_List");
            return UserRole;
        }

        // Select by ID
        public M_UserRole Selectby_id(int UserRoleID)
        {
            var loadmenu = db.SingleOrDefault<M_UserRole>("SELECT * FROM UserRole bc WHERE bc.UserRoleID = " + UserRoleID + ";");
            db.CloseSharedConnection();
            return loadmenu;
        }

        public List<M_UserRole> GetBy_UserID(int UserID)
        {
            var UserRole = db.Fetch<M_UserRole>(@";EXEC UserRole_GetByUserId @@MenuId = @0", UserID);
            return UserRole;
        }

        public List<M_UserRole> GetBy_RoleID(int RoleID)
        {
            var UserRole = db.Fetch<M_UserRole>(@";EXEC UserRole_GetByRoleId @@RoleId = @0", RoleID);
            return UserRole;
        }
    }
}